package core

import (
	"blockchain/crypto"
	"fmt"
)

type Transaction struct {
	Data      []byte
	PublicKey crypto.PublicKey
	Signature *crypto.Signature
}

func (tx *Transaction) Sign(key crypto.PrivateKey) error {
	sig, err := key.Sign(tx.Data)
	if err != nil {
		return err
	}

	tx.PublicKey = key.PublicKey()
	tx.Signature = sig
	return nil
}

func (tx *Transaction) Verify() bool {
	if tx.Signature == nil {
		fmt.Println("No signature")
		return false
	}

	return tx.Signature.Verify(tx.PublicKey, tx.Data)
}
